/**
 * Project of Vehicle Routing Problem with Time Windows implements 
 * some of well-known algorithms for solving VRPTW and presents new 
 * one.
 *
 * @author Michal Drobny  
 */

package logic.car;

import java.util.ArrayList;
import java.util.List;

/*
 * Represents an abstract object for vehicle provider.
 * 
 * @author Michal Drobny
 * @date 25.11.2014
 */
public abstract class VehicleProvider {

	protected final List<Vehicle> vehicles;
	protected int vehicleIndex;

	public VehicleProvider() {
		this.vehicles = new ArrayList<Vehicle>();
		vehicleIndex = 0;
	}

	/**
	 * Constructor.
	 * 
	 * @param vehicles
	 *            The vehicles
	 */
	public VehicleProvider(List<Vehicle> vehicles) {
		if (vehicles == null)
			this.vehicles = new ArrayList<Vehicle>();
		else
			this.vehicles = vehicles;

		this.vehicleIndex = 0;
	}
	
	/**
	 * Gets the current vehicle.
	 * @return the current vehicle
	 */
	public Vehicle getCurrentVehicle() {
		if (vehicles.size() > vehicleIndex)
			return vehicles.get(vehicleIndex);
		else
			return null;
	}

	/**
	 * Method for changing current vehicle for solving Vehicle Routing Problem.
	 * This is the main logic of Vehicle Provider.
	 * 
	 * @param skipToNew Whether the method skip to next vehicle or not
	 * @return Whether the current vehicle was changed or not
	 */
	public abstract boolean nextVehicle(boolean skipToNew);
	
	/**
	 * Method for reseting the state of vehicle provider to the initial state.
	 */
	public abstract void reset();
}